//
//  KFQRPayCodeView.m
//  KafeeSale
//
//  Created by Liboom on 2025/6/28.
//

#import "KFQRPayCodeView.h"
@interface KFQRPayCodeView()
@property(nonatomic, strong) UIImageView *qrView;
@end
@implementation KFQRPayCodeView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
        [self createUI];
    }
    return self;
}
-(void)createUI{
    UIView * bgView = [UIView new];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.cornerRadius = 10;
    [self addSubview:bgView];
    bgView.sd_layout.centerXEqualToView(self).centerYEqualToView(self).widthIs(SCREEN_WIDTH/2);
    
    self.qrView = [UIImageView new];
    self.qrView.image = Image(@"paycode");
    [bgView addSubview:self.qrView];
    self.qrView.sd_layout.leftSpaceToView(bgView, 10).rightSpaceToView(bgView, 10).topSpaceToView(bgView, 10).autoHeightRatio(1.41);
    
    CGFloat btnW =(SCREEN_WIDTH/2 - 30) / 2;
    UIButton * certainBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    certainBtn.backgroundColor = [UIColor colorWithRed:0.15 green:0.61 blue:1 alpha:1];
    [certainBtn setTitle:@"确认收款" forState:UIControlStateNormal];
    [certainBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    certainBtn.titleLabel.font = UIFontMake(14);
    certainBtn.cornerRadius  = 10;
    [certainBtn addTarget:self action:@selector(certainClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:certainBtn];
    certainBtn.sd_layout.leftSpaceToView(bgView, 10).topSpaceToView(self.qrView,0).heightIs(50).widthIs(btnW);
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor whiteColor];
    [btn setTitle:@"取消" forState:UIControlStateNormal];
    [btn setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
    btn.titleLabel.font = UIFontMake(14);
    btn.borderColor = UIColor.lightGrayColor;
    btn.borderWidth = 1;
    btn.cornerRadius  = 10;
    [btn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:btn];
    btn.sd_layout.leftSpaceToView(certainBtn, 10).rightSpaceToView(bgView, 10).topSpaceToView(self.qrView, 0).heightIs(50);
    
    
    
    
    [bgView setupAutoHeightWithBottomView:certainBtn bottomMargin:20];
}
-(void)cancelBtnClick{
    [self removeFromSuperview];
}

-(void)certainClick{
    self.payBlock();
}
@end
